home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / For your think c folder / Classes / CStringDictionary.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-01  |  2.4 KB  |  81 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: CStringDictionary.h
  3.      Major release: Version 1.1d2, 9/5/95
  4.  
  5.      Last modification: Thursday, June 1, 1995, 1:23
  6.      Created: Sunday, July 25, 1993, 18:48
  7.  
  8.      Copyright © 1993-1995, Juri Munkki
  9. /*/
  10.  
  11. /*
  12. **    This class maintains a sort of dictionary of words. The idea
  13. **    is to have a fast way to find a dictionary word. A hashed
  14. **    table is used to speed up the searches while still keeping
  15. **    this class fairly simple.
  16. **
  17. **    NOTE:
  18. **        While data is being added to the object, the
  19. **        object can not be locked.
  20. */
  21. #pragma once
  22. #include "CBaseObject.h"
  23.  
  24. #define    DICTIONARYCLUMPSIZE        (16*sizeof(DictEntry))
  25. #define    WORDCLUMPSIZE            256
  26. #define HASHTABLESIZE            128    /* Must be a power of 2    */
  27.  
  28. /*
  29. **    The amount of storage required for a single item is
  30. **    determined by the token type. A tokentype of "short"
  31. **    will allow 32767 dictionary entries, which should be
  32. **    sufficient for the kinds of data that this class was
  33. **    written for.
  34. */
  35. typedef    short    tokentype;
  36.  
  37. /*
  38. **    Dictionary entries are stored into two separate handles.
  39. **    The other one is the list of words and the other one
  40. **    a list of hash table links and offsets to the words.
  41. */
  42. typedef struct
  43. {
  44.     long    nameOffset;
  45.     short    hashLink;
  46. } DictEntry;
  47.  
  48. class    CStringDictionary : public CBaseObject
  49. {
  50. public:
  51.             /*    Variables:            */
  52.             short        dictCount;                //    Amount of dictionary entries.
  53.             long        logicalDictSize;        //    Used memory of dictionary handle.
  54.             long        realDictSize;            //    Actual size of dictionary handle.
  55.             DictEntry    **dictionary;            //    Handle to dictionary entries.
  56.             
  57.             long        logicalWordListSize;    //    Used memory of word list handle.
  58.             long        realWordListSize;        //    Actual size of word list handle.
  59.             unsigned char **wordList;            //    Word list.
  60.                 
  61.             tokentype    hashTable[HASHTABLESIZE];    //    A hash table is used to accelerate lookups.
  62.  
  63.             /*    Methods:            */    
  64.     virtual    void        IStringDictionary();
  65.     virtual    tokentype    AddDictEntry(unsigned char *entry, short len);
  66.     virtual    tokentype    FindEntry(unsigned char *entry, short len);
  67.     virtual    tokentype    SearchForEntry(unsigned char *entry, short len);
  68.     virtual    void        ReadFromStringList(short strListID);
  69.     
  70.     virtual    short        GetDictionarySize();
  71.     virtual    void        GetIndEntry(short index, StringPtr theEntry);
  72.     
  73.     virtual    void        Dispose();
  74.     virtual    void        Lock();
  75.     virtual    void        Unlock();
  76.  
  77.  
  78.     virtual    short        GetIndEntrySize(short index);
  79.     virtual    Handle        WriteToHandle();
  80.     virtual    void        ReadFromHandle(Handle source);
  81. };